package com.tencent.examples.core.controller;

import com.alibaba.fastjson.JSONObject;
import com.tencent.bk.utils.blueking.properties.ApiUrlProperties;
import com.tencent.bk.utils.blueking.properties.BluekingProperties;
import com.tencent.bk.utils.blueking.properties.ItopProperties;
import com.tencent.bk.utils.blueking.properties.MqProperties;
import com.tencent.examples.blueking.extend.QueryParam;
import com.tencent.examples.blueking.mongo.service.ObjDesService;
import com.tencent.examples.blueking.mysql.model.BkStoreTime;
import com.tencent.examples.blueking.mysql.service.BkStoreTimeService;
import com.tencent.examples.blueking.mysql.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/web/boom")
public class PController {

    @Autowired
    private MessageService messageService;
    @Autowired
    private ObjDesService objDesService;
    @Autowired
    BkStoreTimeService bkStoreTimeService;
    @Autowired
    BluekingProperties bluekingProperties;
    @Autowired
    ItopProperties itopProperties;
    @Autowired
    MqProperties mqProperties;
    @Autowired
    ApiUrlProperties apiUrlProperties;

    @RequestMapping(value = "/success")
    @ResponseBody
    public JSONObject success() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", "0");
        jsonObject.put("msg", "登陆成功");
        return jsonObject;
    }

    @RequestMapping(value = "/test")
    @ResponseBody
    public JSONObject test() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status", "ok");
        return jsonObject;
    }

    @RequestMapping("/save")
    @ResponseBody
    public JSONObject save() {
        BkStoreTime bkStoreTime = new BkStoreTime();
        bkStoreTime.setGlobalId(1L);
        bkStoreTime.setStoreName("lalal");
        bkStoreTimeService.addOrUpdate(bkStoreTime);
        return new JSONObject();
    }

    @RequestMapping("/update")
    @ResponseBody
    public JSONObject update() {
        BkStoreTime bkStoreTime = bkStoreTimeService.findModel(1L);
        bkStoreTime.setStoreName("boom");
        bkStoreTimeService.addOrUpdate(bkStoreTime);
        return new JSONObject();
    }

    @RequestMapping("/delete1")
    @ResponseBody
    public JSONObject delete1() {
        BkStoreTime bkStoreTime = bkStoreTimeService.findModel(1L);
        bkStoreTimeService.delete(bkStoreTime.getId());
        return new JSONObject();
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JSONObject delete() {
        BkStoreTime bkStoreTime = bkStoreTimeService.findModel(1L);
        bkStoreTimeService.delete_logic(bkStoreTime);
        return new JSONObject();
    }

    @RequestMapping(value = "/findList")
    @ResponseBody
    public JSONObject findList() {
        //查全局数据
        List<BkStoreTime> bkStoreTimes = bkStoreTimeService.findList(new QueryParam());
        //分页查询数据
        Sort sort = new Sort(Sort.Direction.DESC, "id");
        Pageable pageable = new PageRequest(0, 2, sort);
        Page<BkStoreTime> bkStoreTimes1 = bkStoreTimeService.findList(pageable, new QueryParam());
        return new JSONObject();
    }

    @RequestMapping(value = "/job")
    @ResponseBody
    public JSONObject job() {
        bkStoreTimeService.storeCloseDay();
        return new JSONObject();
    }
}
